﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using Model.Sys;

namespace BLL
{
    public class RoleBll : BaseBLL
    {
        #region 构造函数

        public RoleBll(LoginInfo info)
        {
            loginInfo = info;
        }
        #endregion

        #region 公共函数

        #region Role
        public RoleInfo GetInfoById(string funID)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetInfoById(funID);
            return result;
        }
        public List<RoleDBInfo> GetUserRole(string userName, string dbName)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetUserRole(userName, dbName);
            return result;
        }
        public int GetUserDBConn(string userName, string dbName)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetUserDBConn(userName, dbName);
            return result;
        }
        public List<RoleInfo> GetList(string funName, string status
    , string expIDs
    , string orderBy, bool asc
    , int pageIndex, int pageSize, out int recordCount)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetList(funName, status
    , expIDs
    , orderBy, asc
    , pageIndex, pageSize, out  recordCount);
            return result;
        }

        public List<RoleInfo> GetByNameWithOutId(string funName, string id = null)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetByNameWithOutId(funName, id);
            return result;
        }

        public int Insert(RoleInfo functionInfo)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.Insert(functionInfo);
            return result;
        }

        public int Update(RoleInfo functionInfo)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.Update(functionInfo);
            return result;
        }

        public int Delete(string funID)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.Delete(funID);
            return result;
        }

        #endregion

        #region DB

        public List<DBInfo> GetAllDB()
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetAllDB();
            return result;
        }

        #endregion

        #region RoleDB

        public List<RoleDBInfo> GetRoleDBByRoleID(string roleId)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetRoleDBByRoleID(roleId);
            return result;
        }

        public int DeleteRoleDB(string roleId, int dbId)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.DeleteRoleDB(roleId, dbId);
            return result;
        }
        public int UpdateRoleDB(RoleDBInfo roledbInfo)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.UpdateRoleDB(roledbInfo);
            return result;
        }
        public int InsertRoleDB(RoleDBInfo roledbInfo)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.InsertRoleDB(roledbInfo);
            return result;
        }
        #endregion

        #region 组内用户

        public List<RoleUserInfo> GetUserByRoleID(string roleId, string userName, string employeeCode
            , string orderBy, bool asc
    , int pageIndex, int pageSize, out int recordCount)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetUserByRoleID(roleId, userName, employeeCode
                , orderBy, asc
    , pageIndex, pageSize, out  recordCount);
            return result;
        }

        public bool GetUserByRoleName(string roleName, string userName)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            return roleDal.GetUserByRoleName(roleName, userName); 
        }
        public int InsertRoleUser(RoleUserInfo roleUserInfo)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.InsertRoleUser(roleUserInfo);
            return result;
        }

        public int DeleteRoleUser(string guid)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.DeleteRoleUser(guid);
            return result;
        }

         #endregion

        #region SysUser

        public bool UpUserStatus(string guid, string status)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            return roleDal.UpUserStatus(guid, status); 
        }
        public SysUserInfo GetUserByUsername(string username)
        {
            RoleDAL roleDal = new RoleDAL(loginInfo);
            var result = roleDal.GetUserByUsername(username);
            return result;
        }
        #endregion

        #endregion
    }
}
